//package com.leyu.mall.site.home.controller;
//import java.io.IOException;
//import java.io.StringWriter;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//import org.codehaus.jackson.JsonEncoding;
//import org.codehaus.jackson.JsonGenerationException;
//import org.codehaus.jackson.JsonGenerator;
//import org.codehaus.jackson.JsonParseException;
//import org.codehaus.jackson.map.JsonMappingException;
//import org.codehaus.jackson.map.ObjectMapper;
//import org.codehaus.jackson.node.JsonNodeFactory;
//import org.codehaus.jackson.xml.XmlMapper;
//import org.junit.After;
//import org.junit.Before;
//import org.junit.Test;
//import com.hoo.entity.AccountBean;
// 
///**
// * <b>function:</b>Jackson 将java对象转换成JSON字符串，也可以将JSON字符串转换成java对象
// * jar-lib-version: jackson-all-1.6.2
// * jettison-1.0.1
// * @author hoojo
// * @createDate 2010-11-23 下午04:54:53
// * @file JacksonTest.java
// * @package com.hoo.test
// * @project Spring3
// * @blog http://blog.csdn.net/IBM_hoojo
// * @email hoojo_@126.com
// * @version 1.0
// */
//@SuppressWarnings("unchecked")
//public class JacksonTest {
//    private JsonGenerator jsonGenerator = null;
//    private ObjectMapper objectMapper = null;
////    private AccountBean bean = null;
//    
//    @Before
//    public void init() {
////        bean = new AccountBean();
////        bean.setAddress("china-Guangzhou");
////        bean.setEmail("hoojo_@126.com");
////        bean.setId(1);
////        bean.setName("hoojo");
//        
//        objectMapper = new ObjectMapper();
//        try {
//            jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(System.out, JsonEncoding.UTF8);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    
//    @After
//    public void destory() {
//        try {
//            if (jsonGenerator != null) {
//                jsonGenerator.flush();
//            }
//            if (!jsonGenerator.isClosed()) {
//                jsonGenerator.close();
//            }
//            jsonGenerator = null;
//            objectMapper = null;
////            bean = null;
//            System.gc();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//    
////    /**
////     * <b>function:</b>将java对象转换成json字符串
////     * @author hoojo
////     * @createDate 2010-11-23 下午06:01:10
////     */
////    @Test
////    public void writeEntityJSON() {
////        
////        try {
////            System.out.println("jsonGenerator");
////            //writeObject可以转换java对象，eg:JavaBean/Map/List/Array等
////            jsonGenerator.writeObject(bean);    
////            System.out.println();
////            
////            System.out.println("ObjectMapper");
////            //writeValue具有和writeObject相同的功能
////            objectMapper.writeValue(System.out, bean);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////    }
//    
////    /**
////     * <b>function:</b>将map转换成json字符串
////     * @author hoojo
////     * @createDate 2010-11-23 下午06:05:26
////     */
////    @Test
////    public void writeMapJSON() {
////        try {
////            Map<String, Object> map = new HashMap<String, Object>();
////            map.put("name", bean.getName());
////            map.put("account", bean);
////            bean = new AccountBean();
////            bean.setAddress("china-Beijin");
////            bean.setEmail("hoojo@qq.com");
////            map.put("account2", bean);
////            
////            System.out.println("jsonGenerator");
////            jsonGenerator.writeObject(map);
////            System.out.println("");
////            
////            System.out.println("objectMapper");
////            objectMapper.writeValue(System.out, map);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////    }
//    
//    
//    /**
//     * <b>function:</b>将list集合转换成json字符串
//     * @author hoojo
//     * @createDate 2010-11-23 下午06:05:59
//     */
//    @Test
//    public void writeListJSON() {
//        try {
//            List<AccountBean> list = new ArrayList<AccountBean>();
//            list.add(bean);
//            
//            bean = new AccountBean();
//            bean.setId(2);
//            bean.setAddress("address2");
//            bean.setEmail("email2");
//            bean.setName("haha2");
//            list.add(bean);
//            
//            System.out.println("jsonGenerator");
//            //list转换成JSON字符串
//            jsonGenerator.writeObject(list);
//            System.out.println();
//            System.out.println("ObjectMapper");
//            //用objectMapper直接返回list转换成的JSON字符串
//            System.out.println("1###" + objectMapper.writeValueAsString(list));
//            System.out.print("2###");
//            //objectMapper list转换成JSON字符串
//            objectMapper.writeValue(System.out, list);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}